package fr.afcepf.atod16.groupe1.projet2.entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;

/**
 * L'entité produit
 * @author cedric
 */
@Entity
@Table(name = "produits")
@NamedQueries({
    @NamedQuery(name="rechercherParCodeEAN13", query="select p from ProduitStock p where p.codeEAN13 = :codeean13")
})
public class ProduitStock implements Serializable, Entite {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;
    @Column(name = "code_ean13", nullable = false, length = 13, unique = true)
    private String codeEAN13;
    @Column(name = "date_creation", nullable = false)
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dateCreation;
    @Column(name = "stock", nullable = false)
    private Integer stock;
    @Column(name = "actif", nullable = false)
    private Boolean actif = false;

    public ProduitStock() {
    }

    public ProduitStock(Integer id, String codeEAN13, Date dateCreation, Integer stock) {
        this.id = id;
        this.codeEAN13 = codeEAN13;
        this.dateCreation = dateCreation;
        this.stock = stock;
    }

    @Override
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCodeEAN13() {
        return codeEAN13;
    }

    public void setCodeEAN13(String codeEAN13) {
        this.codeEAN13 = codeEAN13;
    }

    public Date getDateCreation() {
        return dateCreation;
    }

    public void setDateCreation(Date dateCreation) {
        this.dateCreation = dateCreation;
    }

    public Integer getStock() {
        return stock;
    }

    public void setStock(Integer stock) {
        this.stock = stock;
    }

    public Boolean getActif() {
        return actif;
    }

    public void setActif(Boolean actif) {
        this.actif = actif;
    }

    @Override
    public String toString() {
        return "ProduitStock{" + "id=" + id + ", codeEAN13=" + codeEAN13 + ", dateCreation=" + dateCreation + ", stock=" + stock + ", actif=" + actif + '}';
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 97 * hash + (this.codeEAN13 != null ? this.codeEAN13.hashCode() : 0);
        hash = 97 * hash + (this.dateCreation != null ? this.dateCreation.hashCode() : 0);
        hash = 97 * hash + (this.stock != null ? this.stock.hashCode() : 0);
        hash = 97 * hash + (this.actif != null ? this.actif.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ProduitStock other = (ProduitStock) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if ((this.codeEAN13 == null) ? (other.codeEAN13 != null) : !this.codeEAN13.equals(other.codeEAN13)) {
            return false;
        }
        if (this.dateCreation != other.dateCreation && (this.dateCreation == null || !this.dateCreation.equals(other.dateCreation))) {
            return false;
        }
        if (this.stock != other.stock && (this.stock == null || !this.stock.equals(other.stock))) {
            return false;
        }
        if (this.actif != other.actif && (this.actif == null || !this.actif.equals(other.actif))) {
            return false;
        }
        return true;
    }
}
